<?php
	include_once("bin/connexion.php");
	
	if(isset($_SESSION["user_id"]))
	{
		$id = $_SESSION["user_id"];
		$query = "SELECT * FROM user where id='$id'";
		$result = mysqli_query($bdd,$query);
		$user = mysqli_fetch_array($result);
		$num_biens = 0;
		
		if($user["bailleur"] == 1)
		{
			$query = "SELECT * FROM bien where id_owner='$id'";
			$result = mysqli_query($bdd,$query);
			$num_biens = mysqli_num_rows($result);
		}
		
		$infos = array($user["nom"], $user["prenom"], $user["bailleur"], $user["pic"], $num_biens, $user["mail"], $user["password"]);
	}
	else
	{
		header("location: freebed-login.php");
	}
	
	//update bdd
	if(isset($_POST["envoyer"]))
	{
		
		$nom = $_POST["nom"];
		$prenom = $_POST["prenom"];
		$password = $_POST["password"];
		$mail = $_POST["mail"];
		$query = "UPDATE user SET nom='$nom', prenom='$prenom', password='$password', mail='$mail' WHERE id='$id'";
		mysqli_query($bdd, $query);
	}
	
	include_once("freebed-moduser.html")
?>